package com.example.graduationdesignbackend.controller;


import cn.dev33.satoken.stp.StpUtil;
import com.example.graduationdesignbackend.dto.AdminLoginDto;
import com.example.graduationdesignbackend.dto.UserLoginDto;
import com.example.graduationdesignbackend.entity.Admin;
import com.example.graduationdesignbackend.entity.Product;
import com.example.graduationdesignbackend.query.UserQuery;
import com.example.graduationdesignbackend.res.Res;
import com.example.graduationdesignbackend.service.IAdminService;
import com.example.graduationdesignbackend.service.IProductService;
import com.example.graduationdesignbackend.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuze
 * @since 2024-05-08
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private IProductService productService;
    @Autowired
    private IAdminService adminService;
    @Autowired
    private IUserService userService;
    @GetMapping("/logout")
    public Res logout(){
        StpUtil.logout(StpUtil.getLoginId());
        return Res.yuze();
    }

    @PutMapping ("/editpwd")
    public Res editpwd(@RequestBody Admin admin){
        return adminService.editpwd(admin);
    }

    @PutMapping("/product/examine")
    public Res examine(@RequestBody Product dto){return productService.examine(dto.getId());}

    @PutMapping("/product/examineFail")
    public Res examineFail(@RequestBody Product dto){return productService.examineFail(dto.getId());}

    @GetMapping("/getuser")
    public Res getUser(UserQuery userQuery){return userService.getPage(userQuery);}
}
